﻿namespace AC.ExtendedRenderer.Toolkit.Utils
{
    using System;
    using System.ComponentModel;
    using System.Drawing;

    public class Utility
    {
        public static StringFormat GetStringFormat(ContentAlignment contentAlignment)
        {
            if (!Enum.IsDefined(typeof(ContentAlignment), (int) contentAlignment))
            {
                throw new InvalidEnumArgumentException("contentAlignment", (int) contentAlignment, typeof(ContentAlignment));
            }
            StringFormat format = new StringFormat();
            ContentAlignment alignment = contentAlignment;
            if (alignment <= ContentAlignment.MiddleCenter)
            {
                switch (alignment)
                {
                    case ContentAlignment.TopLeft:
                        format.LineAlignment = StringAlignment.Near;
                        format.Alignment = StringAlignment.Near;
                        return format;

                    case ContentAlignment.TopCenter:
                        format.LineAlignment = StringAlignment.Near;
                        format.Alignment = StringAlignment.Center;
                        return format;

                    case (ContentAlignment.TopCenter | ContentAlignment.TopLeft):
                        return format;

                    case ContentAlignment.TopRight:
                        format.LineAlignment = StringAlignment.Near;
                        format.Alignment = StringAlignment.Far;
                        return format;

                    case ContentAlignment.MiddleLeft:
                        format.LineAlignment = StringAlignment.Center;
                        format.Alignment = StringAlignment.Near;
                        return format;

                    case ContentAlignment.MiddleCenter:
                        format.LineAlignment = StringAlignment.Center;
                        format.Alignment = StringAlignment.Center;
                        return format;
                }
                return format;
            }
            if (alignment <= ContentAlignment.BottomLeft)
            {
                switch (alignment)
                {
                    case ContentAlignment.MiddleRight:
                        format.LineAlignment = StringAlignment.Center;
                        format.Alignment = StringAlignment.Far;
                        return format;

                    case ContentAlignment.BottomLeft:
                        format.LineAlignment = StringAlignment.Far;
                        format.Alignment = StringAlignment.Near;
                        return format;
                }
                return format;
            }
            switch (alignment)
            {
                case ContentAlignment.BottomCenter:
                    format.LineAlignment = StringAlignment.Far;
                    format.Alignment = StringAlignment.Center;
                    return format;

                case ContentAlignment.BottomRight:
                    format.LineAlignment = StringAlignment.Far;
                    format.Alignment = StringAlignment.Far;
                    return format;
            }
            return format;
        }

        public static bool IsVista()
        {
            return (Environment.OSVersion.Version.Major >= 6);
        }
    }
}

